<?php
/**
 * +----------------------------------------------------------------------
 * | Author: 罗极
 * +----------------------------------------------------------------------
 * | Description: Loader.php
 * +----------------------------------------------------------------------
 * | User: Administrator Date: 8/20/ 0020 Time: 10:00
 * +----------------------------------------------------------------------
 */
namespace Framework\Loader;

class Loader
{
    /**
     * @return bool
     */
    public static function init() : bool
    {
        return spl_autoload_register(__CLASS__.'::autoload');
    }

    public static function autoload(string $class)
    {
        $class      = ltrim($class, '\\');
        $fileName   = BASE_PATH.DS.str_replace('\\', '/', $class).'.php';

        if(!file_exists($fileName)) {
            throw new \RuntimeException(sprintf('找不到类文件:[%s]', $fileName));
        }

        require $fileName;
    }
}